package com.huaxin.hxcloud.Adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.huaxin.common.Entity.RepairTaskDetailDTO;
import com.huaxin.hxcloud.R;

/**
 * @author songxf
 * @date 2018/7/17
 * @Desc $desc$
 * Copyright HUAXIN DATA. All rights reserved.
 */
public class HxSpttroCauseDlogAdapter extends BaseQuickAdapter<RepairTaskDetailDTO.Data.malfunctionReason, BaseViewHolder> {
    private final Resources mResources;
    private int mWorkTaskState = 0;

    public HxSpttroCauseDlogAdapter(Context context, int workTaskState) {
        super(R.layout.item_cause);
        mResources = context.getResources();
        mWorkTaskState = workTaskState;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final RepairTaskDetailDTO.Data.malfunctionReason item) {
        final TextView itemTv = helper.getView(R.id.item_tv);
        itemTv.setText(item.getName());
        if (item.isSelect()) {
            itemTv.setTextColor(mResources.getColor(R.color.bt_blue));
            itemTv.setBackgroundResource(R.drawable.item_blue_select_bg);
        } else {
            itemTv.setTextColor(mResources.getColor(R.color.color_333333));
            itemTv.setBackgroundResource(R.drawable.item_gray_unselect_bg);
        }
        //站点巡检单状态:0、未派工;1、已派工;2、处理中; 3已完成
        switch (mWorkTaskState) {
            case 0:
            case 1:
            case 3:
            default:
                itemTv.setEnabled(false);
                break;
            case 2:
                itemTv.setEnabled(true);
                break;

        }
        itemTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HxSpttroCauseDlogAdapter.this.remove(helper.getLayoutPosition());
                item.setSelect(!item.isSelect());
                if (item.isSelect()) {
                    HxSpttroCauseDlogAdapter.this.addData(0, item);
                    itemTv.setBackgroundResource(R.drawable.item_blue_select_bg);
                    itemTv.setTextColor(mResources.getColor(R.color.bt_blue));
                } else {
                    HxSpttroCauseDlogAdapter.this.addData(item);
                    itemTv.setBackgroundResource(R.drawable.item_gray_unselect_bg);
                    itemTv.setTextColor(mResources.getColor(R.color.color_333333));
                }
            }
        });
    }
}
